let fs=require("fs");
let path=require("path");
let router=require("koa-router")()
function name() {
        let files=fs.readdirSync(__dirname)
        console.log(files);
        return files.filter(name=>{
            return name.endsWith(".js")&& name!=="index.js"
        })
}

function add(filePath) {
    console.log(filePath);
    filePath.forEach(itme => {
        let fun=path.join(__dirname,itme)
        let uid=require(fun)
        for(let i in uid){
            console.log(i);
            let type=uid[i][0]
            let x=uid[i][1]
            console.log(x);
            if(type==="get"){
                router.get(i,x)
            }else{
              router.post(i,x)
            }
        }
        
    });
    
}

 module.exports=function() {
     let names=name();
     add(names)
  return  router.routes()
 }